import { MigrationInterface, QueryRunner, Table, Index } from 'typeorm';

export class CreateSiteCategoryMapTable20250210000001 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: 'site_category_maps',
        columns: [
          {
            name: 'id',
            type: 'int',
            isPrimary: true,
            isGenerated: true,
            generationStrategy: 'increment',
          },
          {
            name: 'site',
            type: 'varchar',
            length: '20',
            comment: '站点名称',
          },
          {
            name: 'siteCategory',
            type: 'varchar',
            length: '50',
            comment: '源站分类名',
          },
          {
            name: 'masterId',
            type: 'tinyint',
            comment: '母分类ID',
          },
          {
            name: 'status',
            type: 'tinyint',
            default: 1,
            comment: '状态: 0-禁用 1-启用',
          },
          {
            name: 'description',
            type: 'text',
            isNullable: true,
            comment: '映射说明',
          },
          {
            name: 'createdAt',
            type: 'timestamp',
            default: 'CURRENT_TIMESTAMP',
          },
          {
            name: 'updatedAt',
            type: 'timestamp',
            default: 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
          },
        ],
      }),
      true,
    );

    // 索引创建暂时跳过，可以通过其他方式创建
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable('site_category_maps');
  }
}